using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Entities;
using BUS;
using Utility;

public partial class Admin_CuaHangUpdate : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadDropDownList();
            LoadData();
        }
    }
    private  void LoadDropDownList()
    {
        tbSanPhamCollection spCollection = tbSanPhamBUS.GetAll();
        ddl_sanpham.DataTextField = tbSanPhamColumns.TenSP.ToString();
        ddl_sanpham.DataValueField = tbSanPhamColumns.MaSP.ToString();
        ddl_sanpham.DataSource = spCollection;
        ddl_sanpham.DataBind();
        ddl_sanpham.Items.Insert(0, new ListItem("All", "0"));
    }
    private void LoadData()
    {
        try
        {
            int iD=int.Parse (Request .QueryString ["iD"].ToString ());
            txt_macuahang.Text=iD.ToString ();
            tbCuaHang cuahang=tbCuaHangBUS .GetByID (iD);
            txt_tencuahang .Text=cuahang .TenCH ;
            ddl_sanpham .SelectedValue =cuahang .SanPham .ToString ();
        }
        catch 
        {
            Response.Redirect("~/Admin/CuaHangDanhSach.aspx");
        }

    }
    protected void btn_sua_Click(object sender, EventArgs e)
    {
        try
        {
            int iD = int.Parse(Request.QueryString["iD"].ToString());
            tbCuaHang cuahang = tbCuaHangBUS.GetByID(iD);
            cuahang.TenCH = txt_tencuahang.Text;
            cuahang.SanPham = int.Parse(ddl_sanpham.SelectedValue);
            tbCuaHangBUS.Update(cuahang);
        }
        catch
        {
        }
        Response.Redirect("~/Admin/CuaHangDanhSach.aspx");
        Response.Redirect(Request.RawUrl);
    }
}
